import Home from "@/pages/Home"
import Login from "@/pages/Login"
import Register from "@/pages/Register"
import Search from "@/pages/Search"
import Detail from "@/pages/Detail"
import AddCartSuccess from "@/pages/AddCartSuccess"
export default [
    {
        path: '/center',
        name: 'center',
        /*
        路由懒加载，将组件的引入作为函数返回值，只有当组件被访问时函数才会调用，实现按需加载
        */
        component: () => import('@/pages/Center'),
        meta: {
            isshow: true
        },
        //二级路由
        children: [
            {
                path: 'myorder',
                component: () => import('@/pages/Center/Myorder')
            },
            {
                path: 'grouporder',
                component: () => import('@/pages/Center/Grouporder')
            },
            //重定向:访问center时重定向到/center/myorder
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    },
    {
        path: '/paysuccess',
        name: 'paysuccess',
        component: () => import('@/pages/PaySuccess'),
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            if (from.path == '/pay') {
                next()
            } else {
                next(false)
            }
        },
        meta: {
            isshow: true
        }
    },
    {
        path: '/pay',
        name: 'pay',
        component: () => import('@/pages/Pay'),
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            if (from.path == '/trade') {
                next()
            } else {
                next(false)
            }
        },
        meta: {
            isshow: true
        }
    },
    {
        path: '/trade',
        name: 'trade',
        component: () => import('@/pages/Trade'),
        //路由独享守卫
        beforeEnter: (to, from, next) => {
            //去交易页面必须是从购物车来，其他界面来停留在当前
            if (from.path == '/shopcart') {
                next()
            } else {
                next(false)
            }
        },
        meta: {
            isshow: true
        }
    },
    {
        path: '/shopcart',
        name: 'shopcart',
        component: () => import('@/pages/ShopCart'),
        meta: {
            isshow: true
        }
    },
    {
        path: '/addcartsuccess',
        name: 'addcartsuccess',
        component: AddCartSuccess,
        meta: {
            isshow: true
        }
    },
    {
        path: '/home',
        name: 'home',
        component: Home,
        // 路由元信息，用于保存自定义数据 
        meta: {
            isshow: true
        }
    },
    {
        path: '/detail/:skuid',
        name: 'detail',
        component: Detail,
        meta: {
            isshow: true
        }
    },
    {
        path: '/login',
        name: 'login',
        component: Login,
        meta: {
            isshow: false
        }
    },
    {
        path: '/register',
        name: 'register',
        component: Register,
        meta: {
            isshow: false
        }
    },
    {
        path: '/search/:keyword?',//在parmas参数占位符后面加？指定改参数可传可不传
        name: 'search',
        component: Search,
        meta: {
            isshow: true
        }
    },
    //重定向
    {
        path: '*',
        redirect: '/home'
    }
]